package com.example.esp8266_wifi_control;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.Parcelable;
import android.util.Log;

public class MyBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null
                && WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
            Log.e("======", "NETWORK_STATE_CHANGED_ACTION");
            Parcelable parcelable = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
            if (parcelable != null) {
                NetworkInfo networkInfo = (NetworkInfo) parcelable;
                NetworkInfo.State state = networkInfo.getState();
                boolean isConnect = state == NetworkInfo.State.CONNECTED;
                Log.e("======", "isConnect=" + isConnect);
            }
        }
    }
}